package com.aispeech.asr.webase.seaweedfs.client;

import com.aispeech.asr.webase.seaweedfs.client.cache.LookupCache;
import com.aispeech.asr.webase.seaweedfs.client.cache.MapLookupCache;
import com.aispeech.asr.webase.seaweedfs.client.exceptions.WeedFSException;
import com.aispeech.asr.webase.seaweedfs.client.impl.SeaWeedFSClientImpl;
import org.springframework.web.reactive.function.client.WebClient;

public class SeaWeedFSClientBuilder {
    LookupCache lookupCache;
    WebClient webClient;
    String masterUrl = "http://localhost:9333";

    public SeaWeedFSClientBuilder() {
    }

    public SeaWeedFSClientBuilder masterUrl(String masterUrl) {
        this.masterUrl = masterUrl;
        return this;
    }

    public SeaWeedFSClientBuilder webClient(WebClient webClient) {
        this.webClient = webClient;
        return this;
    }

    public SeaWeedFSClientBuilder lookupCache(LookupCache lookupCache) {
        this.lookupCache = lookupCache;
        return this;
    }

    public SeaWeedFSClient build() throws WeedFSException {
        if (webClient == null) {
            throw new WeedFSException("webClient is null");
        }

        if (masterUrl == null) {
            throw new WeedFSException("masterUrl is null");
        }

        if (lookupCache == null)
            lookupCache = new MapLookupCache();

        return new SeaWeedFSClientImpl(webClient, masterUrl, lookupCache);
    }

}
